package cn.samler.shopapi.Controller;

import cn.samler.shopapi.Model.Sys.Response;
import cn.samler.shopapi.Service.BannerService;
import cn.samler.shopapi.Service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("home")
public class HomeController {
    private final BannerService bannerService;
    private final GoodsService goodsService;

    HomeController(BannerService bannerService, GoodsService goodsService) {
        this.bannerService = bannerService;
        this.goodsService = goodsService;
    }

    /**
     * 获取首页banner数据
     *
     * @return List<Banner>
     */
    @GetMapping("banners")
    public Response getBanners() {
        return Response.success(bannerService.findAll());
    }

    /**
     * 获取首页热门商品
     *
     * @return List<GoodsBrief>
     */
    @GetMapping("hot_goods")
    public Response getHotGoods() {
        return Response.success(goodsService.getGoodsByHot());
    }

    /**
     * 获取首页上新商品
     *
     * @return List<GoodsBrief>
     */
    @GetMapping("newest_goods")
    public Response getNewestGoods() {
        return Response.success(goodsService.getGoodsByNewest());
    }
}
